#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>

int main()
{
  pid_t id = fork();
  if(id == 0)
  {
    int cnt = 5;
    while(cnt)
    {
      printf("child id running,pid:%d,ppid:%d\n",getpid(),getppid());
      sleep(1);
      cnt--;
    }
    exit(0);
  }
  printf("父进程正在休眠\n");
  sleep(10);
  printf("父进程开始回收\n");
//  pid_t rid = wait(NULL);
  int status = 0;
  pid_t rid=waitpid(id,&status,0);
  if(rid > 0)
  {
    printf("wait success,rid:%d,staus:%d\n",rid,status);
  }
  printf("父进程回收僵尸\n");
  sleep(3);
  return 0;
}
